package com.ruoyi.sl.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.sl.domain.SlSpecialAttendance;
import com.ruoyi.sl.service.ISlSpecialAttendanceService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 特殊考勤天数Controller
 * 
 * @author admin
 * @date 2024-07-11
 */
@RestController
@RequestMapping("/sl/sattendance")
public class SlSpecialAttendanceController extends BaseController
{
    @Autowired
    private ISlSpecialAttendanceService slSpecialAttendanceService;

    /**
     * 查询特殊考勤天数列表
     */
    @PreAuthorize("@ss.hasPermi('sl:sattendance:list')")
    @GetMapping("/list")
    public TableDataInfo list(SlSpecialAttendance slSpecialAttendance)
    {
        startPage();
        List<SlSpecialAttendance> list = slSpecialAttendanceService.selectSlSpecialAttendanceList(slSpecialAttendance);
        return getDataTable(list);
    }

    /**
     * 导出特殊考勤天数列表
     */
    @PreAuthorize("@ss.hasPermi('sl:sattendance:export')")
    @Log(title = "特殊考勤天数", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SlSpecialAttendance slSpecialAttendance)
    {
        List<SlSpecialAttendance> list = slSpecialAttendanceService.selectSlSpecialAttendanceList(slSpecialAttendance);
        ExcelUtil<SlSpecialAttendance> util = new ExcelUtil<SlSpecialAttendance>(SlSpecialAttendance.class);
        util.exportExcel(response, list, "特殊考勤天数数据");
    }

    /**
     * 获取特殊考勤天数详细信息
     */
    @PreAuthorize("@ss.hasPermi('sl:sattendance:query')")
    @GetMapping(value = "/{sattendanceId}")
    public AjaxResult getInfo(@PathVariable("sattendanceId") Long sattendanceId)
    {
        return success(slSpecialAttendanceService.selectSlSpecialAttendanceBySattendanceId(sattendanceId));
    }

    /**
     * 新增特殊考勤天数
     */
    @PreAuthorize("@ss.hasPermi('sl:sattendance:add')")
    @Log(title = "特殊考勤天数", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SlSpecialAttendance slSpecialAttendance)
    {
        if (!slSpecialAttendanceService.checkSlSpecialAttendanceByDeptId(slSpecialAttendance))
        {
            return error("新增失败,部门ID'" + slSpecialAttendance.getDeptId() + "'的记录已存在");
        }
        return toAjax(slSpecialAttendanceService.insertSlSpecialAttendance(slSpecialAttendance));
    }

    /**
     * 修改特殊考勤天数
     */
    @PreAuthorize("@ss.hasPermi('sl:sattendance:edit')")
    @Log(title = "特殊考勤天数", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SlSpecialAttendance slSpecialAttendance)
    {
        if (!slSpecialAttendanceService.checkSlSpecialAttendanceByDeptId(slSpecialAttendance))
        {
            return error("新增失败,部门ID'" + slSpecialAttendance.getDeptId() + "'的记录已存在");
        }
        return toAjax(slSpecialAttendanceService.updateSlSpecialAttendance(slSpecialAttendance));
    }

    /**
     * 删除特殊考勤天数
     */
    @PreAuthorize("@ss.hasPermi('sl:sattendance:remove')")
    @Log(title = "特殊考勤天数", businessType = BusinessType.DELETE)
	@DeleteMapping("/{sattendanceIds}")
    public AjaxResult remove(@PathVariable Long[] sattendanceIds)
    {
        return toAjax(slSpecialAttendanceService.deleteSlSpecialAttendanceBySattendanceIds(sattendanceIds));
    }
}
